//-----------------------------------------------------
//variable definition
//-----------------------------------------------------

//OS
var mac = (navigator.appVersion.indexOf('Mac') != -1)? true : false;
var win = (navigator.appVersion.indexOf('Win') != -1)? true : false;

//browser
var nn = (navigator.appName.indexOf('Netscape',0) != -1)? true : false;
var nn4 = (document.layers)? true : false;
var opera6 = (navigator.userAgent.indexOf('Opera/6') != -1)? true : false;
var opera5 = (navigator.userAgent.indexOf('Opera/5') != -1)? true : false;
var icab = (navigator.userAgent.indexOf('iCab') != -1)? true : false;
var ie = (navigator.userAgent && navigator.userAgent.indexOf('MSIE')>=0)? true : false;
var ie4 = navigator.userAgent.indexOf('MSIE 4') != -1;
var ie5 = (navigator.userAgent.indexOf('MSIE 5') != -1)? true : false;

// 画面項目を更新した時の色
var editColor = "#F0FDE0";



//-----------------------------------------------------
//set css
//-----------------------------------------------------

var cssFile;

if(mac){
	if(nn4){
		cssFile = '../css/for_macnn4.css';
	}
	if(ie4){
		cssFile = '../css/for_macie4.css';
	}
}else{
	if(nn4){
		cssFile = '../css/for_winnn4.css';
	}
}

if(cssFile){
	if (document.getElementById && !opera5 && !opera6 && !(mac && ie5) && !icab){
		var head = document.getElementsByTagName('HEAD').item(0);
		var newLink = document.createElement('LINK');
		newLink.rel = 'stylesheet';
		newLink.type = 'text/css';
		newLink.href = cssFile;
		head.appendChild(newLink);
	}else{
		document.open();
		document.write('<link rel="stylesheet" href="' + cssFile + '" type="text/css">');
		document.close();
	}
}




//-----------------------------------------------------
//swap image
//-----------------------------------------------------

function swapImage(targetImg,imageSrc) {
	if(!document.images)return;
	document.images[targetImg].src = imageSrc;
}




//-----------------------------------------------------
//window
//-----------------------------------------------------

//window.focus();
//window.name = 'dch';




//-----------------------------------------------------
//window open
//-----------------------------------------------------

function checkEvent(targetObj,windowW,windowH,scrollbarOption,eventObj){
	var eventType;
	var keycode;

	if(window.event){
		keycode = event.keyCode;
		eventType = event.type;
	}
	else if(eventObj){
		keycode = eventObj.which;
		eventType = eventObj.type;
	}

	if(keycode == 13 && eventType == 'keypress'){
		openFigWindow(targetObj,windowW,windowH,scrollbarOption);
	}
}


function openFigWindow(targetObj,windowW,windowH,scrollbarOption){
	var windowName = targetObj.target;
	var uri = targetObj.href;

	if(scrollbarOption && opera6){
		windowW = windowW -15;
	}
	if(scrollbarOption && win && ie){
		windowW = windowW +15;
	}

	var options = 'toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=' + (scrollbarOption?'yes':'no') + ',resizable=yes,width=' + windowW + ',height=' + windowH;

	if(!window.scrollbars){
		//if(scrollbarOption)windowName += '_02';
	}

	newWindow = window.open(uri,windowName,options);
	newWindow.focus();

	if(newWindow.scrollbars){
		if(scrollbarOption){
			newWindow.scrollbars.visible = true;
		}
		else{
			newWindow.scrollbars.visible = false;
		}
	}

	if(!(typeof newWindow.resizeBy == 'undefined')){
		var newWindowW = 0;
		var newWindowH = 0;
		var differenceW = 0;
		var differenceH = 0;

		if(scrollbarOption && win && ie){
			windowW = windowW - 30;
		}

		//Opera,Safari,over NN4
		if(newWindow.innerWidth){
			newWindowW = newWindow.innerWidth;
			newWindowH = newWindow.innerHeight;
		}

		//WinIE6 standardmode
		else if(newWindow.document.compatMode == 'CSS1Compat'){
			newWindowW = newWindow.document.documentElement.clientWidth;
			newWindowH = newWindow.document.documentElement.clientHeight;
		}

		//over IE5
		else if(newWindow.document.body && newWindow.document.body.clientWidth){
			newWindowW = newWindow.document.body.clientWidth;
			newWindowH = newWindow.document.body.clientHeight;
		}

		if(newWindowW && newWindowH){
			differenceW = (scrollbarOption?windowW+15:windowW) - newWindowW;
			differenceH = windowH - newWindowH;
			newWindow.resizeBy(differenceW,differenceH);
		}
	}
}


// ElementId(部品ID)指定で色換え
function chageBackgroundColorById( id )
{
	var e = document.all.item( id );
	e.style.backgroundColor = editColor;
}

// ElementId(部品ID)指定した、親の要素を色換え
function chageParentBackgroundColorById( id )
{
	var e = document.all.item(id).parentElement;
	e.style.backgroundColor = editColor;
}

// ElementId(部品ID)指定した親の要素を色換え
// (部品がテーブルタグで囲まれている場合に使用。主にSelectOneMenu用)
function chageParentBackgroundColorByIdAtSelectOne( id )
{
	var e = document.all.item( id ).parentNode.parentNode.parentNode.parentNode.parentNode;
	e.style.backgroundColor = editColor;
}

// ElementId(部品ID)指定した親要素の親要素の子要素（複数）を色換え
// (部品がテーブルタグで囲まれている場合に使用。主にSelectOneMenu用)
function chageParentGroupBackgroundColorByIdAtSelectOne( id )
{
	var es = document.all.item( id ).parentNode.parentNode.childNodes;
	for (i = 0 ; i < es.length ; i++ )
	{
		es[i].style.backgroundColor = editColor;
	}
}


// ElementId(部品ID)指定した親要素の親要素の子要素（複数）を色換え
// (部品がテーブルタグで囲まれている場合に使用。主にSelectOneMenu用)
function chageParentGroupBackgroundColorByThis( ctl )
{
	var e = ctl.parentElement;
	e.style.backgroundColor = editColor;
}


function chageParentGroupBackgroundColorByParent(ctl)
{
	var sid = ctl.id;

	var ids = sid.split(':');

	if(ids[2] != null){

		document.getElementById('Edit:terminalTableC:' + ids[2] + ':_id104').style.backgroundColor = editColor;

	}
}

function changeExamDrop(){

	var sp = document.getElementById('Edit:terminalTableC:6:_id153');
	if(sp){
		sp.style.backgroundColor = editColor;
	}
}


var send = false;



function sendCheck(){

	// <removed by=s-kamoshita date=2006/06/26>
	//	ID:750対応
	// if(send){
	// 	return false;
	// }else{
	// 	send = true;
	// 	return true;
	// }
	// </removed>
}
//window.openByPost 実装
function openByPost(url, element, name )
{
    var win = window.open( "about:blank", name, 'width=650, height=1000, menubar=no, toolbar=no, scrollbars=yes' );

    // formを生成
    var form = $(document.createElement("form"));

    form.attr('target',name);
    form.attr('action',url);
    form.attr('method','post');

    form.append(element);
    // 一時的にbodyへformを追加。サブミット後、formを削除する
    var body = $($("body")[0]);
    body.append(form);
    form.submit();
    form.remove();
    return win;
}

